package float
{
   import command.DoTweenMax;
   
   import flash.display.Sprite;
   import flash.events.Event;
   import flash.geom.Point;
   
   import jp.progression.casts.CastMovieClip;

   /**
    * This is a black-transparent edition.
    * @author  cjboy1984@gmail.com
    * @usage   see MyFloat.as
    */
   public class BaseFloat extends CastMovieClip
   {
      // fla
      public var btnClose:MyButton;
      
      // blocker
      private var blocker:Sprite = new Sprite();

      public function BaseFloat( initObject:Object = null )
      {
         super( initObject );

         stop();

         addChildAt(blocker, 0);
      }

      // --------------------- LINE ---------------------

      // ################### protected ##################

      override protected function atCastAdded():void
      {
         // basic
         onStageResize();
         stage.addEventListener(Event.RESIZE, onStageResize);
         
         // close button
         btnClose.buttonMode = true;
         btnClose.onClick = function()
         {
            this.buttonMode = false;
            MyFloat.remove();
         };

         // animation
         blocker.alpha = 0.7;
         alpha = 0;
         addCommand(
            new DoTweenMax(this, 0.35, { alpha:1 } )
         );
      }

      override protected function atCastRemoved():void
      {
         stage.removeEventListener(Event.RESIZE, onStageResize);

         // animation
         addCommand(
            new DoTweenMax(this, 0.2, { alpha:0 } )
         );
      }

      // #################### private ###################

      private function onStageResize(e:Event = null)
      {
         x = orgX;
         y = orgY;

         var p:Point = globalToLocal(new Point(0, 0));
         blocker.graphics.clear();
         blocker.graphics.beginFill(0x000000);
         blocker.graphics.drawRect(p.x, p.y, sw, sh);
         blocker.graphics.endFill();
      }

      // Original x,y-pos
      private function get orgX():Number { return sw / 2; }
      private function get orgY():Number { return sh / 2; }

      private function get sw():Number { return stage.stageWidth; }
      private function get sh():Number { return stage.stageHeight; }

      // --------------------- LINE ---------------------

   }

}
